package cc.autoapi.pucong.auto.flow.provider.properties.controller;

import cc.autoapi.pucong.auto.flow.core.root.entity.BatchDeleteIdDto;
import cc.autoapi.pucong.auto.flow.core.root.exception.AutoFlowBaseController;
import cc.autoapi.pucong.auto.flow.core.root.exception.AutoFlowExceptionHandler;
import cc.autoapi.pucong.auto.flow.core.root.utils.Res;
import cc.autoapi.pucong.auto.flow.provider.properties.manager.PropertiesInfoManager;
import cc.autoapi.pucong.auto.flow.provider.properties.entity.dto.PropertiesInfoAddDto;
import cc.autoapi.pucong.auto.flow.provider.properties.entity.dto.PropertiesInfoUpdateDto;
import cc.autoapi.pucong.auto.flow.provider.properties.entity.qo.PropertiesInfoQo;
import cc.autoapi.pucong.auto.flow.provider.properties.entity.vo.PropertiesInfoTreeVo;
import cc.autoapi.pucong.auto.flow.provider.properties.entity.vo.PropertiesInfoVo;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author pucong
 * @description 全局参数信息 controller
 * @create 2024-10-06
 */
@RestController
@Validated
@RequestMapping("/properties/propertiesInfo")
public class PropertiesInfoController extends AutoFlowBaseController implements AutoFlowExceptionHandler{

    @Resource
    private PropertiesInfoManager propertiesInfoManager;

    @GetMapping("/getList")
    public Res<List<PropertiesInfoVo>> getList(PropertiesInfoQo dto) {
        List<PropertiesInfoVo> propertiesInfoList = propertiesInfoManager.getList(dto);
        return Res.ok(propertiesInfoList);
    }

    @GetMapping("/getTree2")
    public Res<List<PropertiesInfoTreeVo>> getTree2(PropertiesInfoQo dto) {
        List<PropertiesInfoTreeVo> propertiesInfoList = propertiesInfoManager.getTree2(dto);
        return Res.ok(propertiesInfoList);
    }

    @GetMapping("/getTree")
    public Res<List<PropertiesInfoTreeVo>> getTree(PropertiesInfoQo dto) {
        List<PropertiesInfoTreeVo> propertiesInfoList = propertiesInfoManager.getTree(dto);
        return Res.ok(propertiesInfoList);
    }

    @GetMapping("/getDetailById/{id}")
    public Res<PropertiesInfoVo> getDetailById(@PathVariable("id") String id) {
        PropertiesInfoVo propertiesInfoDto = propertiesInfoManager.getDetailById(id);
        return Res.ok(propertiesInfoDto);
    }

    @PostMapping("/add")
    public Res<String> add(@RequestBody PropertiesInfoAddDto dto) {
        String id = propertiesInfoManager.add(dto);
        return Res.ok(id);
    }

    @PostMapping("/updateById/{id}")
    public Res<Boolean> updateById(@PathVariable("id") String id,
                                   @RequestBody PropertiesInfoUpdateDto dto) {
        Boolean i = propertiesInfoManager.updateById(id, dto);
        return Res.ok(i);
    }

    @DeleteMapping("/batchDeleteByIds")
    public Res<Boolean> batchDeleteByIds(BatchDeleteIdDto dto) {
        Boolean i = propertiesInfoManager.batchDeleteByIds(dto.getIdList());
        return Res.ok(i);
    }
}
